using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class Tf_event_log {
		#region Fields
		private int id;
		private int uid;
		private string user_nick_name;
		private string user_pic;
		private int ele_id;
		private string ele_name;
		private string log_type;
		private DateTime keyin_date = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the Tf_event_log class.
		/// </summary>
		public Tf_event_log() {
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_event_log class.
		/// </summary>
		public Tf_event_log(int uid, string user_nick_name, string user_pic, int ele_id, string ele_name, string log_type, DateTime keyin_date) {
			this.uid = uid;
			this.user_nick_name = user_nick_name;
			this.user_pic = user_pic;
			this.ele_id = ele_id;
			this.ele_name = ele_name;
			this.log_type = log_type;
			this.keyin_date = keyin_date;
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_event_log class.
		/// </summary>
		public Tf_event_log(int id, int uid, string user_nick_name, string user_pic, int ele_id, string ele_name, string log_type, DateTime keyin_date) {
			this.id = id;
			this.uid = uid;
			this.user_nick_name = user_nick_name;
			this.user_pic = user_pic;
			this.ele_id = ele_id;
			this.ele_name = ele_name;
			this.log_type = log_type;
			this.keyin_date = keyin_date;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Uid value.
		/// </summary>
		public int Uid {
			get { return uid; }
			set { uid = value; }
		}
		
		/// <summary>
		/// Gets or sets the User_nick_name value.
		/// </summary>
		public string User_nick_name {
			get { return user_nick_name; }
			set { user_nick_name = value; }
		}
		
		/// <summary>
		/// Gets or sets the User_pic value.
		/// </summary>
		public string User_pic {
			get { return user_pic; }
			set { user_pic = value; }
		}
		
		/// <summary>
		/// Gets or sets the Ele_id value.
		/// </summary>
		public int Ele_id {
			get { return ele_id; }
			set { ele_id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Ele_name value.
		/// </summary>
		public string Ele_name {
			get { return ele_name; }
			set { ele_name = value; }
		}
		
		/// <summary>
		/// Gets or sets the Log_type value.
		/// </summary>
		public string Log_type {
			get { return log_type; }
			set { log_type = value; }
		}
		
		/// <summary>
		/// Gets or sets the Keyin_date value.
		/// </summary>
		public DateTime Keyin_date {
			get { return keyin_date; }
			set { keyin_date = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the tf_event_log table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("tf_event_logInsert", uid, user_nick_name, user_pic, ele_id, ele_name, log_type, keyin_date));
		}
		
		/// <summary>
		/// Updates a record in the tf_event_log table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("tf_event_logUpdate", id, uid, user_nick_name, user_pic, ele_id, ele_name, log_type, keyin_date);
		}
		
		/// <summary>
		/// Deletes a record from the tf_event_log table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("tf_event_logDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the tf_event_log table.
		/// </summary>
		public static Tf_event_log Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_event_logSelect", id)) {
				if (dataReader.Read()) {
					return MakeTf_event_log(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the tf_event_log table.
		/// </summary>
		public static List<Tf_event_log> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_event_logSelectAll")) {
				List<Tf_event_log> tf_event_logList = new List<Tf_event_log>();
				while (dataReader.Read()) {
					Tf_event_log tf_event_log = MakeTf_event_log(dataReader);
					tf_event_logList.Add(tf_event_log);
				}
				return tf_event_logList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the tf_event_log class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static Tf_event_log MakeTf_event_log(SqlDataReader dataReader) {
			Tf_event_log tf_event_log = new Tf_event_log();
			
			if (dataReader.IsDBNull(0) == false) {
				tf_event_log.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tf_event_log.Uid = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tf_event_log.User_nick_name = dataReader.GetString(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tf_event_log.User_pic = dataReader.GetString(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tf_event_log.Ele_id = dataReader.GetInt32(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tf_event_log.Ele_name = dataReader.GetString(5);
			}
			if (dataReader.IsDBNull(6) == false) {
				tf_event_log.Log_type = dataReader.GetString(6);
			}
			if (dataReader.IsDBNull(7) == false) {
				tf_event_log.Keyin_date = dataReader.GetDateTime(7);
			}

			return tf_event_log;
		}
		#endregion
	}
}
